home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Sample Code / Movie Toolbox / Inside Mac Movie Toolbox Code / mtb15.c < prev    next >
Encoding:
Text File  |  1994-12-05  |  2.2 KB  |  102 lines  |  [TEXT/MPS ]

  1. /*
  2.   File:            mtb15.c
  3.   Contains:        Track Matte Functions
  4.   Written by:    DTS and QT Engineering
  5.   Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  6.   Change History (most recent first):
  7.   <1>         12/4/94    khs        changed the format of the file to the new look and feel
  8.   To Do:
  9. */
  10.  
  11.  
  12. // INCLUDES
  13. #include "mtb.h"
  14.  
  15.  
  16. // FUNCTIONS
  17. void CreateTrackMatte(Track theTrack)
  18. {
  19.     QDErr err;
  20.     GWorldPtr aGW;
  21.     Rect trackBox;
  22.     Fixed trackHeight;
  23.     Fixed trackWidth;
  24.     CTabHandle grayCTab;
  25.  
  26.     GetTrackDimensions(theTrack, &trackWidth, &trackHeight);
  27.     SetRect(&trackBox, 0, 0, FixRound(trackWidth), FixRound(trackHeight));
  28.  
  29.     grayCTab = GetCTable(40);                    // 8 bit + 32 = 8 bit gray 
  30.     err = NewGWorld(&aGW, 8, &trackBox, grayCTab, (GDHandle)nil, 0);
  31.     DisposeCTable(grayCTab);
  32.     if (!err && (aGW != nil))
  33.     {
  34.         SetTrackMatte(theTrack, aGW->portPixMap);
  35.         DisposeGWorld(aGW);
  36.     }
  37. }
  38.  
  39.  
  40. void UpdateTrackMatte(Track theTrack)
  41. {
  42.     OSErr err;
  43.     PixMapHandle trackMatte;
  44.     PixMapHandle savePortPix;
  45.     Movie theMovie;
  46.     GWorldPtr tempGW;
  47.     CGrafPtr savePort;
  48.     GDHandle saveGDevice;
  49.     Rect matteBox;
  50.     short i;
  51.  
  52.     theMovie = GetTrackMovie(theTrack);
  53.     trackMatte = GetTrackMatte(theTrack);
  54.     if (trackMatte == nil)
  55.     {
  56.         // track doesn't have a matte, so give it one
  57.         CreateTrackMatte(theTrack);
  58.         trackMatte = GetTrackMatte(theTrack);
  59.         if (trackMatte == nil)
  60.             return;
  61.     }
  62.  
  63.     GetGWorld(&savePort, &saveGDevice);
  64.     matteBox = (**trackMatte).bounds;
  65.     err = NewGWorld(&tempGW, (**trackMatte).pixelSize, &matteBox, (**trackMatte).pmTable, (GDHandle)nil, 0);
  66.     if (err || (tempGW == nil))
  67.         return;
  68.  
  69.     SetGWorld(tempGW, nil);
  70.     savePortPix = tempGW->portPixMap;
  71.     LockPixels(trackMatte);
  72.     SetPortPix(trackMatte);
  73.  
  74.     // draw a gray ramp rectangle around the edge of the matte     
  75.     for (i = 0; i < 35; i++)
  76.     {
  77.         RGBColor aColor;
  78.         long tempLong;
  79.  
  80.         tempLong = 65536 - ((65536 / 35) * (long)i);
  81.         aColor.red = aColor.green = aColor.blue = tempLong;
  82.         RGBForeColor(&aColor);
  83.         FrameRect(&matteBox);
  84.         InsetRect(&matteBox, 1, 1);
  85.     }
  86.  
  87.     // fill the center of the matte with black
  88.     ForeColor(blackColor);
  89.     PaintRect(&matteBox);
  90.  
  91.     SetPortPix(savePortPix);
  92.     SetGWorld(savePort, saveGDevice);
  93.     DisposeGWorld(tempGW);
  94.  
  95.     UnlockPixels(trackMatte);
  96.     SetTrackMatte(theTrack, trackMatte);
  97.  
  98.     DisposeMatte(trackMatte);
  99. }
  100.  
  101.  
  102.